//
//  EAGLView.h
//  CrazyDice
//
//  Created by Hjelm Daniel on 7/20/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

#import <OpenGLES/EAGL.h>
#import <OpenGLES/EAGLDrawable.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>

#import "PVRTexture.h"
#import "DiceModel.h"
#import "MainBackgroundModel.h"

/*
typedef struct
{
	BOOL rotstop; // stop self rotation
	BOOL touchInside; // finger tap inside of the object ?
	BOOL scalestart; // start to scale the obejct ?
	CGPoint pos; // position of the object on the screen
	CGPoint startTouchPosition; // Start Touch Position
	CGPoint currentTouchPosition; // Current Touch Position
	GLfloat pinchDistance; // distance between two fingers pinch
	GLfloat pinchDistanceShown; // distance that have shown on screen
	GLfloat scale; // OpenGL scale factor of the object
	GLfloat rotation; // OpenGL rotation factor of the object
	GLfloat rotspeed; // control rotation speed of the object
} ObjectData;
*/

// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
// The view content is basically an EAGL surface you render your OpenGL scene into.
// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
@interface EAGLView : UIView
{    
@private
    BOOL animating;
    BOOL displayLinkSupported;
    NSInteger animationFrameInterval;
    // Use of the CADisplayLink class is the preferred method for controlling your animation timing.
    // CADisplayLink will link to the main display and fire every vsync when added to a given run-loop.
    // The NSTimer class is used only as fallback when running on a pre 3.1 device where CADisplayLink
    // isn't available.
    id displayLink;
    NSTimer *animationTimer;
	
	
	EAGLContext *context;
	
    // The pixel dimensions of the CAEAGLLayer
    GLint backingWidth;
    GLint backingHeight;
	
    // The OpenGL ES names for the framebuffer and renderbuffer used to render to this view
    GLuint defaultFramebuffer, colorRenderbuffer;
	
	DiceModel *bwdice; // Black and white dice
	MainBackgroundModel *background; // Game background
}

@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
@property (nonatomic) NSInteger animationFrameInterval;

- (void)startAnimation;
- (void)stopAnimation;
- (void)drawView:(id)sender;

@end
